package com.mytest.provider.es.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: llq
 * @Date: 2020/4/8
 */
@RestController
@RequestMapping("/es")
public class EsController {

    /*@Autowired
    BookMpper bookMpper;*/

    /*@RequestMapping("/springdata/book/{id}")
    public BookEntity getBookById(@PathVariable String id){
        //测试内置的findById
        Optional<BookEntity> optional=bookMpper.findById(id);
        BookEntity bookEntity=optional.get();
        return bookEntity;
    }

    @RequestMapping("/springdata/search/{key}")
    public List<BookEntity> search(@PathVariable String key){
        //测试全文搜索
        List<BookEntity> list=bookMpper.getByMessage(key);
        return list;
    }

    @RequestMapping("/springdata/search/{key}/{page}")
    public List<BookEntity> search(@PathVariable int page,@PathVariable String key){
        int numberOfPage=5;
        PageRequest pageRequest= PageRequest.of(page,numberOfPage);
        //全文搜索翻页
        Page<BookEntity> pages=bookMpper.getByMessage(key,pageRequest);

        long total=pages.getTotalElements();
        long totalPage=pages.getTotalPages();

        List<BookEntity> list=pages.getContent();
        return  list;
    }*/

}
